package com.jucai.pppeiyouclient.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * app 首次启动记录工具包
 */
public class FirstLaunchUtils {

    private static final String LAUNCH_NAME_ID = "firstLaunchID";
    private static final String SHARED_PREFERENCES_NAME = "firstLaunch";
    private static final String LAUNCH_MAIN_ID = "firstMainId";

    /**
     * 是否已经第一次运行过
     *
     * @param context
     * @return
     */
    public static boolean isLaunched(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
        return preferences.getString(LAUNCH_NAME_ID, null) == null ? false : true;
    }

    public static void firstLaunch(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.putString(LAUNCH_NAME_ID, "go");
        editor.commit();
    }

    /**
     * 判断是否是 第一次进入首页
     *
     * @param context
     * @return
     */
    public static boolean isFirstMain(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
        return preferences.getString(LAUNCH_MAIN_ID, null) == null ? false : true;
    }

    public static void firstMain(Context context) {
        SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
        Editor editor = preferences.edit();
        editor.putString(LAUNCH_MAIN_ID, "go");
        editor.commit();
    }
}
